import React, { Component, PropTypes } from 'react'
import { hashHistory } from 'react-router'
import { Icon } from 'antd-mobile'

export default class TopNavHeader extends Component {
  render() {
    const { title, onClick } = this.props
    return (
      <div className={`cm-navbar-box`}>
        <Icon
          type="left"
          onClick={() => {
            if ('function' === typeof onClick) {
              onClick()
              return
            }
            hashHistory.goBack()
          }}
        />
        <span>{title}</span>
      </div>
    )
  }
}

TopNavHeader.propTypes = {
  title: PropTypes.string.isRequired,
  onClick: PropTypes.func,
}